<?php
$userid = get_session('findpwd_userid');
if(empty($userid)){
	go('./index.php?mdl=findpwd&do=account');
}
$userinfo = $__oUser->get_by_userid($userid, '`userid`,`username`,`nickname`,`email`,`password_faq`,`password_ans`');
if(empty($userinfo['nickname']))$userinfo['nickname'] = $userinfo['username'];

if(empty($_POST['formAction'])){
	$userinfo['email'] = preg_replace('/^(\w)\w+(\w)/i', '$1****$2', $userinfo['email']);
	$vars['userinfo'] = $userinfo;
}else{
	$resend = empty($_POST['resend']) ? 0 : 1;
	$_str = serialize(array(
		'userid'	=> $userinfo['userid'],
		'email'		=> $userinfo['email'],
	));
	$confirm_code	= base64_encode(php_authcode($_str, $operation = 'ENCODE', $key = '', $expiry = 86400 * 2));
	$confirm_url	= WEB_URL."index.php?mdl=findpwd&do=reset&code={$confirm_code}";

	$oMail = new Mail($__f_sysvars['email_smtp_server'], 'smtp');
	$sr = $oMail->send('findpwd_email', $userinfo['email'], $userinfo['nickname'], array(
		'nickname'		=> $userinfo['nickname'],
		'subject'		=> "{$userinfo['nickname']},找回密码邮箱验证",
		'altbody'		=> "请将地址复制到您的浏览器(例如IE)的地址栏访问：{$confirm_url}",
		'confirm_url'	=> $confirm_url,
	), $resend);
	if($sr == 'succ'){
		ajax_msg('succ', '', 'callback_findpwd_method');
	}
	ajax_msg('warning', $sr, 'callback_findpwd_method');
}

?>